package nancal.mp.db.mongo.table

import java.io.*
import nbcp.base.db.*
import nbcp.base.comm.*
import nbcp.base.extend.*
import nbcp.base.enums.*
import nbcp.base.utils.*
import nbcp.myoql.db.*
import nbcp.myoql.db.comm.*
import nbcp.myoql.db.enums.*
import nbcp.myoql.db.mongo.*
import nbcp.myoql.db.mongo.base.*
import nbcp.myoql.db.mongo.component.*
import org.slf4j.LoggerFactory
import org.springframework.stereotype.*


@Component("mongo.wx")
@MetaDataGroup(DatabaseEnum.Mongo, "wx")
class WxGroup : IDataGroup {
    override fun getEntities(): Set<BaseMetaData<out Any>> = setOf(appUserInnerMessage, wxAppLoginUser, wxAppUser, wxFormId)



    val appUserInnerMessage get() = AppUserInnerMessageEntity();




    val wxAppLoginUser get() = WxAppLoginUserEntity();




    val wxAppUser get() = WxAppUserEntity();




    val wxFormId get() = WxFormIdEntity();



    @org.springframework.data.mongodb.core.mapping.Document()
    @nbcp.base.db.annotation.DbEntityGroup(value = """wx""")
    @nbcp.myoql.db.comm.RemoveToSysDustbin
    class AppUserInnerMessageEntity(collectionName: String = "appUserInnerMessage") :
        MongoBaseMetaCollection<nancal.mp.db.mongo.entity.wx.AppUserInnerMessage>(nancal.mp.db.mongo.entity.wx.AppUserInnerMessage::class.java, collectionName) {

        val id = MongoColumnName("_id")

        val type = MongoColumnName("type")

        val user = IdNameMeta("user")

        val title = MongoColumnName("title")

        val content = MongoColumnName("content")

        val data = MongoColumnName("data")

        val read = MongoColumnName("read")

        val readAt = MongoColumnName("readAt")

        val sender = IdNameMeta("sender")

        val sendAt = MongoColumnName("sendAt")

        /**
         * 创建时间
         */
        @nbcp.base.db.annotation.Cn(value = """创建时间""") 
        val createAt = MongoColumnName("createAt")

        /**
         * 更新时间
         */
        @nbcp.base.db.annotation.Cn(value = """更新时间""") 
        val updateAt = MongoColumnName("updateAt")

    }


    @org.springframework.data.mongodb.core.mapping.Document()
    @nbcp.base.db.annotation.DbEntityGroup(value = """wx""")
    @nbcp.base.db.annotation.DbEntityIndex(value = arrayOf("""id"""), unique = true)
    @nbcp.base.db.annotation.DbEntityIndexes(value = arrayOf(nbcp.base.db.annotation.DbEntityIndex(value = arrayOf("""loginName"""), unique = true)))
    class WxAppLoginUserEntity(collectionName: String = "wxAppLoginUser") :
        MongoBaseMetaCollection<nancal.mp.db.mongo.entity.wx.WxAppLoginUser>(nancal.mp.db.mongo.entity.wx.WxAppLoginUser::class.java, collectionName) {

        val id = MongoColumnName("_id")

        val errorLoginTimes = MongoColumnName("errorLoginTimes")

        /**
         * 登录名
         */
        @nbcp.base.db.annotation.Cn(value = """登录名""") 
        val loginName = MongoColumnName("loginName")

        /**
         * 登录手机
         */
        @nbcp.base.db.annotation.Cn(value = """登录手机""") 
        val mobile = MongoColumnName("mobile")

        /**
         * 登录邮箱
         */
        @nbcp.base.db.annotation.Cn(value = """登录邮箱""") 
        val email = MongoColumnName("email")

        /**
         * 密码
         */
        @nbcp.base.db.annotation.Cn(value = """密码""") 
        val password = MongoColumnName("password")

        /**
         * 最后登录时间
         */
        @nbcp.base.db.annotation.Cn(value = """最后登录时间""") 
        val lastLoginAt = MongoColumnName("lastLoginAt")

        /**
         * 是否已锁定
         */
        @nbcp.base.db.annotation.Cn(value = """是否已锁定""") 
        val isLocked = MongoColumnName("isLocked")

        /**
         * 锁定详情
         */
        @nbcp.base.db.annotation.Cn(value = """锁定详情""") 
        val lockedRemark = MongoColumnName("lockedRemark")

        /**
         * 创建时间
         */
        @nbcp.base.db.annotation.Cn(value = """创建时间""") 
        val createAt = MongoColumnName("createAt")

        /**
         * 更新时间
         */
        @nbcp.base.db.annotation.Cn(value = """更新时间""") 
        val updateAt = MongoColumnName("updateAt")

        fun queryByLoginName(loginName: String): MongoQueryClip<WxAppLoginUserEntity, nancal.mp.db.mongo.entity.wx.WxAppLoginUser> {
            return this.query().where { it.loginName mongoEquals loginName }
        }


        fun deleteByLoginName(loginName: String): MongoDeleteClip<WxAppLoginUserEntity> {
            return this.delete().where { it.loginName mongoEquals loginName }
        }

        fun updateByLoginName(loginName: String): MongoUpdateClip<WxAppLoginUserEntity, nancal.mp.db.mongo.entity.wx.WxAppLoginUser> {
            return this.update().where { it.loginName mongoEquals loginName }
        }
        
        


        fun queryById(id: String): MongoQueryClip<WxAppLoginUserEntity, nancal.mp.db.mongo.entity.wx.WxAppLoginUser> {
            return this.query().where { it.id mongoEquals id }
        }


        fun deleteById(id: String): MongoDeleteClip<WxAppLoginUserEntity> {
            return this.delete().where { it.id mongoEquals id }
        }

        fun updateById(id: String): MongoUpdateClip<WxAppLoginUserEntity, nancal.mp.db.mongo.entity.wx.WxAppLoginUser> {
            return this.update().where { it.id mongoEquals id }
        }
        
        

    }


    @org.springframework.data.mongodb.core.mapping.Document()
    @nbcp.base.db.annotation.DbEntityGroup(value = """wx""")
    @nbcp.base.db.annotation.DbEntityIndexes(value = arrayOf(nbcp.base.db.annotation.DbEntityIndex(value = arrayOf("""wxUserInfo.openid"""), unique = true)))
    @nbcp.myoql.db.comm.RemoveToSysDustbin
    class WxAppUserEntity(collectionName: String = "wxAppUser") :
        MongoBaseMetaCollection<nancal.mp.db.mongo.entity.wx.WxAppUser>(nancal.mp.db.mongo.entity.wx.WxAppUser::class.java, collectionName) {

        val id = MongoColumnName("_id")

        /**
         * 昵称
         */
        @nbcp.base.db.annotation.Cn(value = """昵称""") 
        val name = MongoColumnName("name")

        val partnerType = MongoColumnName("partnerType")

        val role = MongoColumnName("role")

        val wxUserInfo = WxUserDataMeta("wxUserInfo")

        val commission = MongoColumnName("commission")

        val superior = OpenIdNameUrlMeta("superior")

        val qrCodeScene = MongoColumnName("qrCodeScene")

        val qrCodeSceneCreateAt = MongoColumnName("qrCodeSceneCreateAt")

        val receiveAddresses = ReceiveAddressDataInfoMeta("receiveAddresses")

        val invoices = BaseInvoiceDataMeta("invoices")

        val scores = MongoColumnName("scores")

        val isLocked = MongoColumnName("isLocked")

        val lockedRemark = MongoColumnName("lockedRemark")

        /**
         * 登录名
         */
        @nbcp.base.db.annotation.Cn(value = """登录名""") 
        val loginName = MongoColumnName("loginName")

        /**
         * 手机号
         */
        @nbcp.base.db.annotation.Cn(value = """手机号""") 
        val mobile = MongoColumnName("mobile")

        /**
         * 电子邮件
         */
        @nbcp.base.db.annotation.Cn(value = """电子邮件""") 
        val email = MongoColumnName("email")

        /**
         * 头像
         */
        @nbcp.base.db.annotation.Cn(value = """头像""") 
        val logo = IdUrlMeta("logo")

        /**
         * 备注
         */
        @nbcp.base.db.annotation.Cn(value = """备注""") 
        val remark = MongoColumnName("remark")

        /**
         * 身份证
         */
        @nbcp.base.db.annotation.Cn(value = """身份证""") 
        val identityCard = IdentityCardDataMeta("identityCard")

        /**
         * 创建时间
         */
        @nbcp.base.db.annotation.Cn(value = """创建时间""") 
        val createAt = MongoColumnName("createAt")

        /**
         * 更新时间
         */
        @nbcp.base.db.annotation.Cn(value = """更新时间""") 
        val updateAt = MongoColumnName("updateAt")

        fun queryByWxUserInfoOpenid(wxUserInfoOpenid: String): MongoQueryClip<WxAppUserEntity, nancal.mp.db.mongo.entity.wx.WxAppUser> {
            return this.query().where { it.wxUserInfo.openid mongoEquals wxUserInfoOpenid }
        }


        fun deleteByWxUserInfoOpenid(wxUserInfoOpenid: String): MongoDeleteClip<WxAppUserEntity> {
            return this.delete().where { it.wxUserInfo.openid mongoEquals wxUserInfoOpenid }
        }

        fun updateByWxUserInfoOpenid(wxUserInfoOpenid: String): MongoUpdateClip<WxAppUserEntity, nancal.mp.db.mongo.entity.wx.WxAppUser> {
            return this.update().where { it.wxUserInfo.openid mongoEquals wxUserInfoOpenid }
        }
        
        

    }


    @org.springframework.data.mongodb.core.mapping.Document()
    @nbcp.base.db.annotation.DbEntityGroup(value = """wx""")
    class WxFormIdEntity(collectionName: String = "wxFormId") :
        MongoBaseMetaCollection<nancal.mp.db.mongo.entity.wx.WxFormId>(nancal.mp.db.mongo.entity.wx.WxFormId::class.java, collectionName) {

        val id = MongoColumnName("_id")

        val openid = MongoColumnName("openid")

        val formId = MongoColumnName("formId")

        val prePayId = MongoColumnName("prePayId")

        val used = MongoColumnName("used")

        val usedAt = MongoColumnName("usedAt")

        /**
         * 创建时间
         */
        @nbcp.base.db.annotation.Cn(value = """创建时间""") 
        val createAt = MongoColumnName("createAt")

        /**
         * 更新时间
         */
        @nbcp.base.db.annotation.Cn(value = """更新时间""") 
        val updateAt = MongoColumnName("updateAt")

    }

}

